package com.wsc.controller;

import java.io.File;
import java.io.FileNotFoundException;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;

public class ControllerDetails {
	static String server_doc_root,controller_server_ip,crawler_server_ip;
	static int controller_port,crawler_port;
	static XMLConfiguration config = null;
	
	public static void loadXmlFile() throws FileNotFoundException {
		File f;
		f = new File("config/controller-properties.xml");
		try {
			config = new XMLConfiguration(f);

			// config.load();
		} catch (ConfigurationException e) {
			e.printStackTrace();
		}
		// set expression engine to exexute xpath queries on config.xml file

		config.setExpressionEngine(new XPathExpressionEngine());
	}
	
	public static void getAllDetails(){
		server_doc_root = (String) config
				.getProperty("/property/entry[@name='Controller-Server-Doc-Root']");
		controller_port = Integer.parseInt((String) config
				.getProperty("/property/entry[@name='Controller-Server-Port']"));
		crawler_port = Integer.parseInt((String) config
				.getProperty("/property/entry[@name='Crawler-Server-Port']"));
		controller_server_ip = (String) config
				.getProperty("/property/entry[@name='Controller-Server-IP']");
		crawler_server_ip = (String) config
				.getProperty("/property/entry[@name='Crawler-Server-IP']");
		
	}
	
	
	//getter methods
	public static  String getControllerServerIP() {
		return controller_server_ip;
	}
	
	public static  String getCrawlerServerIP() {
		return crawler_server_ip;
	}
	
	public static  String getServerRootDirectory() {
		return server_doc_root;
	}
	
	public static int getControllerServerPort() {
		return controller_port;
	}
	
	public static int getCrawlerServerPort() {
		return crawler_port;
	}

}
